/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package databaseupgrade;

import TimeRecording.Upgrade.SqlCommandStatusType;
import java.awt.Component;
import javax.swing.ImageIcon;
import javax.swing.JTable;
import javax.swing.SwingConstants;
import javax.swing.table.DefaultTableCellRenderer;

/**
 *
 * @author dpatchett
 */
public class SqlCommandStatusRenderer extends DefaultTableCellRenderer {

    private static boolean imagesLoaded = false;
    private static ImageIcon notYetRun;
    private static ImageIcon executing;
    private static ImageIcon failed;
    private static ImageIcon succeeded;

    @Override
    public Component getTableCellRendererComponent(JTable table, Object value,
            boolean isSelected, boolean hasFocus, int row, int column) {

        if (!imagesLoaded) {
            notYetRun = new ImageIcon(getClass().getResource("/blank.png"));
            executing = new ImageIcon(getClass().getResource("/lightning.png"));
            failed = new ImageIcon(getClass().getResource("/cross.png"));
            succeeded = new ImageIcon(getClass().getResource("/tick.png"));
            imagesLoaded = true;
        }

        SqlCommandStatusType status = (SqlCommandStatusType) value;
        this.setHorizontalAlignment(SwingConstants.CENTER);

        if (status == null) {
            this.setIcon(notYetRun);
            
        } else {
            switch (status) {
                case NOT_YET_RUN:
                    this.setIcon(notYetRun);
                    break;
                case EXECUTING:
                    this.setIcon(executing);
                    break;
                case FAILED:
                    this.setIcon(failed);
                    break;
                case SUCCEEDED:
                    this.setIcon(succeeded);
                    break;
            }
        }

        return this;
    }
}
